import 'package:my_shop/timer/timer_task_config.dart';
import 'package:my_shop/timer/timer_task_id.dart';
import 'package:my_shop/util/extension/list_extension.dart';
import 'package:flutter/material.dart';

/// 定时任务配置管理
class TimerTaskConfigManager {
  static final TimerTaskConfigManager _instance = TimerTaskConfigManager._internal();

  factory TimerTaskConfigManager() => _instance;

  TimerTaskConfigManager._internal();

  /// 获取所有定时任务配置
  List<TimerTaskConfig> getAllTaskConfigs() {
    return [
      // 数据同步任务
      TimerTaskConfig(
        taskId: TimerTaskId.syncData,
        interval: const Duration(minutes: 30),
        callback: () {
          // TODO: 实现数据同步逻辑
        },
        executeImmediately: true,
      ),
      
      // 数据备份任务
      TimerTaskConfig(
        taskId: TimerTaskId.dataBackup,
        specificTime: const TimeOfDay(hour: 2, minute: 0),
        callback: () {
          // TODO: 实现数据备份逻辑
        },
        executeImmediately: false,
      ),
      
      // 清理缓存任务
      TimerTaskConfig(
        taskId: TimerTaskId.clearCache,
        interval: const Duration(hours: 24),
        callback: () {
          // TODO: 实现缓存清理逻辑
        },
        executeImmediately: false,
      ),
    ];
  }

  /// 获取指定ID的任务配置
  TimerTaskConfig? getTaskConfig(TimerTaskId taskId) {
    return getAllTaskConfigs().firstWhereOrNull(
      (config) => config.taskId == taskId,
    );
  }
}